package com.zlm.common.util;

import org.apache.commons.lang3.tuple.Pair;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * 日期时间辅助工具类。
 * 
 * @author duxiangwei
 * @date 2015-11-04
 * @version 1.0.0
 * @Copyright © 2015 www.longsoftware.com
 */
public class DateTimeUtils {
	// 日期默认格式
    public static final String FORMAT_DATE_DEFAULT = "yyyy-MM-dd";
	// 日期格式没有分隔符
    public static final String FORMAT_DATE_NO_SEPARATOR = "yyyyMMdd";
	// 默认时间格式
    public static final String FORMAT_DATETIME_DEFAULT = "yyyy-MM-dd HH:mm:ss";
	// 时间格式没有秒
    public static final String FORMAT_DATETIME_NO_SECHODE = "yyyy-MM-dd HH:mm";
	// 时间格式没有年月日
    public static final String FORMAT_DATETIME_NO_YEARMD = "HH:mm:ss";

    public static final String FORMAT_DATETIME_HOUR_MIN = "HH:mm";

    public static final String FORMAT_YEAR_MONTH = "yyyy-MM";

    public static final String FORMAT_MONTH_DAY = "MM-dd";

    public static final String FORMAT_DATETIME_NO_SEPARATOR = "yyyyMMddHHmmss";




	/**
	 * 时间相加多少小时。
	 * 
	 * @param day
	 * @param x
	 * @return
	 */
	public static String addDateHour(String day, int x) {
		SimpleDateFormat format = new SimpleDateFormat(FORMAT_DATETIME_NO_SECHODE);// 24小时制
		Date date = null;
		try {
			date = format.parse(day);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		if (date == null) {
			return "";
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DECEMBER, x);// 24小时制
		date = cal.getTime();
		cal = null;
		return format.format(date);

	}

	public static Date addDay(int day) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DAY_OF_MONTH, day);
		return calendar.getTime();
	}

	/**
	 * 将日期格式转换为字符串。
	 * 
	 * @param date
	 * @return
	 * @author cary.liu
	 */
	public static String date2String(Date date) {
		if (date == null) {
			return null;
		}
		String dateStr = new SimpleDateFormat(FORMAT_DATE_DEFAULT).format(date);
		return dateStr;
	}

	/**
	 * 将日期格式转换为字符串。
	 * 
	 * @param date
	 * @return
	 * @author cary.liu
	 */
	public static String datetime2String(Date date) {
		if (date == null) {
			return null;
		}
		String dateStr = new SimpleDateFormat(FORMAT_DATETIME_DEFAULT).format(date);
		return dateStr;
	}

	/**
	 * 将日期格式转换为字符串。
	 *
	 * @param date
	 * @return
	 * @author cary.liu
	 */
	public static String datetime3String(Date date) {
		if (date == null) {
			return null;
		}
		String dateStr = new SimpleDateFormat(FORMAT_DATETIME_NO_YEARMD).format(date);
		return dateStr;
	}

	/**
	 * 将日期格式转换为字符串。
	 *
	 * @param date
	 * @return
	 * @author cary.liu
	 */
	public static String datetime4String(Date date) {
		if (date == null) {
			return null;
		}
		String dateStr = new SimpleDateFormat(FORMAT_MONTH_DAY).format(date);
		return dateStr;
	}

	/**
	 * 格式化
	 * @param date
	 * @param format
	 * @return
	 */
	public static String datetime5String(Date date,String format) {
		if (date == null) {
			return null;
		}
		String dateStr = new SimpleDateFormat(format).format(date);
		return dateStr;
	}



	/**
	 * 字符串转换为日期
	 * 
	 * @param dateStr
	 * @return
	 */
	public static Date dateString2Date(String dateStr) {
		SimpleDateFormat dateformat = new SimpleDateFormat(FORMAT_YEAR_MONTH);
		Date date = null;
		try {
			if (dateStr == null || "".equals(dateStr)) {
				return null;
			}
			date = dateformat.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		return date;
	}

	public static Date String2Date(String dateStr) {
		SimpleDateFormat dateformat = new SimpleDateFormat(FORMAT_DATE_DEFAULT);
		Date date = null;
		try {
			if (dateStr == null || "".equals(dateStr)) {
				return null;
			}
			date = dateformat.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		return date;
	}

	/**
	 * 字符串转换为日期
	 *
	 * @param dateStr
	 * @param format
	 * @return
	 */
	public static Date dateString2Date(String dateStr, String format) {
		SimpleDateFormat dateformat = new SimpleDateFormat(format);
		Date date = null;
		try {
			if (dateStr == null || "".equals(dateStr)) {
				return null;
			}
			date = dateformat.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		return date;
	}

	/**
	 * 返回当前日期。
	 * 
	 * @return
	 * @create 2012-8-31 上午09:18:35
	 */
	public static String getCurrentDateString() {
		Date date = new Date();
		SimpleDateFormat dateformat = new SimpleDateFormat(FORMAT_DATE_DEFAULT);
		return dateformat.format(date);
	}

	/**
	 * 获取当前时间(包含时分秒)。
	 * 
	 * @return
	 * @author cary.liu
	 */
	public static Date getCurrentDateTime() {
		return new Date(System.currentTimeMillis());
	}

	/**
	 * 获取当前时间(指定格式)。
	 * 
	 * @param formatStr
	 * @return
	 * @author cary.liu
	 */
	public static String getCurrentDateTimeString(String formatStr) {
		Date date = new Date();
		SimpleDateFormat formater = null;
		if (formatStr == null || "".equals("")) {
			formater = new SimpleDateFormat(FORMAT_DATETIME_DEFAULT);
		} else {
			formater = new SimpleDateFormat(formatStr);
		}
		return formater.format(date);
	}

	/**
	 * 时间加上 days天数.
	 * 
	 * @param days
	 * @return
	 */
	public static String getCurrentTimeAddDay(int days) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + days);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.format(calendar.getTime());
	}

	/**
	 * 获取当前时间戳
	 * 
	 * @return
	 * @author cary.liu
	 */
	public static Timestamp getCurrentTimestamp() {
		return new Timestamp(System.currentTimeMillis());
	}

	/**
	 * 获取时间戳
	 * @return
	 * @author duyufu
	 */
	public static String getTimestamp(){
		return String.valueOf(System.currentTimeMillis());
	}

	/**
	 * 时间戳转换成日期格式字符串
	 * @param seconds 精确到秒的字符串
	 * @param format
	 * @return
	 */
	public static String timeStamp2Date(String seconds,String format) {
		if(seconds == null || seconds.isEmpty() || seconds.equals("null")){
			 return "";
	     }
	    if(format == null || format.isEmpty()){
			 format = "yyyy-MM-dd HH:mm:ss";
		 }
		SimpleDateFormat sdf = new SimpleDateFormat(format);
	    if (seconds.length()== 10 ) {
			return sdf.format(new Date(Long.valueOf(seconds+"000")));
		}
		return sdf.format(new Date(Long.valueOf(seconds)));
	}

	/*
     * 将时间转换为时间戳
     */
    public static Integer dateToStamp(Date date){
        return Integer.parseInt(String.valueOf(date.getTime()/1000));
    }

    /*
     * 将字符串转换为时间戳
     */
    public static Integer dateToStamp(String s) throws ParseException{
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_DATETIME_DEFAULT);
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime()/1000;
        res = String.valueOf(ts);
        return Integer.parseInt(res);
    }

	/*
	 * 将时间转换为时间戳
	 */
//	public static String date2Stamp(String s) throws ParseException{
//		String res;
//		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_DATETIME_DEFAULT);
//		Date date = simpleDateFormat.parse(s);
//		long ts = date.getTime();
//		res = String.valueOf(ts);
//		return res;
//	}

	/*
	 * 将时间戳转换为时间
	 */
//	public static String stampToDate(String s){
//		String res;
//		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_DATETIME_DEFAULT);
//		long lt = new Long(s);
//		Date date = new Date(lt);
//		res = simpleDateFormat.format(date);
//		return res;
//	}


	public static Integer getCurrentTime() {
		long nowTime = System.currentTimeMillis()/1000;
		return Integer.parseInt(String.valueOf(nowTime));
	}

	public static Date getDate() {
		return new Date();
	}

	/**
	 * 获取日期个时间的年月日格式。
	 * 
	 * @param
	 * @return
	 */
	public static Date getDate(Date date) {
		SimpleDateFormat dateformat = new SimpleDateFormat(FORMAT_DATE_DEFAULT);
		if (date != null) {
			try {
				date = dateformat.parse(dateformat.format(date));
			} catch (ParseException e) {
				e.printStackTrace();
				return null;
			}
		}
		return date;
	}

	/**
	 * 得到某个时间几天后的时间。
	 * 
	 * @param d
	 * @param day
	 * @return
	 */
	public static Date getDateAfter(Date d, int day) {
		Calendar now = Calendar.getInstance();
		now.setTime(d);
		now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
		return now.getTime();
	}

	/**
	 * 得到某个时间几天前的日期。
	 * 
	 * @param d
	 * @param day
	 * @return
	 */
	public static Date getDateBefore(Date d, int day) {
		Calendar now = Calendar.getInstance();
		now.setTime(d);
		now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
		return now.getTime();
	}

	/**
	 * 根据日期获取日。
	 * 
	 * @param date
	 * @return
	 * @author cary.liu
	 */
	public static Integer getDayNo(Date date) {
		if (date == null) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.DATE);
	}

	/**
	 * 返回两个日期相差的天数。
	 * 
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public static BigDecimal getDifferDayNumber(Date startDate, Date endDate) {
		long totalDate = 0;
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		long timestart = calendar.getTimeInMillis();
		calendar.setTime(endDate);
		long timeend = calendar.getTimeInMillis();
		totalDate = Math.abs((timeend - timestart)) / (1000 * 60 * 60 * 24);
		return new BigDecimal(totalDate).setScale(2,BigDecimal.ROUND_HALF_UP);
	}

	/**
	 * 返回两个日期相差的分钟数。
	 * 
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public static long getDifferMinuteNumber(Date startDate, Date endDate) {
		long totalMins = 0;
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		long timestart = calendar.getTimeInMillis();
		calendar.setTime(endDate);
		long timeend = calendar.getTimeInMillis();
		totalMins = Math.abs((timeend - timestart)) / (1000 * 60);
		return totalMins;
	}

	/**
	 * 返回两个日期相差的小时数。
	 *
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public static BigDecimal getDifferHourNumber(Date startDate, Date endDate) {
		double totalMins = 0;
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		long timestart = calendar.getTimeInMillis();
		calendar.setTime(endDate);
		long timeend = calendar.getTimeInMillis();
		totalMins =(double) Math.abs((timeend - timestart))/ (1000 * 60 * 60);
		return new BigDecimal(totalMins).setScale(2,BigDecimal.ROUND_HALF_UP);
	}

	/**
	 * 返回两个相差的分钟。
	 * 
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public static long getDifferMinuteNumber(long startDate, long endDate) {
		long totalMins = (endDate - startDate) / 1000 / 60;
		return totalMins;
	}

	/**
	 * 根据日期获取月份。
	 * 
	 * @param date
	 * @return
	 * @author cary.liu
	 */
	public static Integer getMonthNo(Date date) {
		if (date == null) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.MONTH) + 1;
	}

	/**
	 * 获取几分钟后的时间。
	 * 
	 * @param minutes
	 * @return
	 */
	public static Date getTimeAddMinute(int minutes) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MINUTE, minutes);
		return calendar.getTime();
	}

	/**
	 * 获取当前的年和月。
	 * 
	 * @return
	 * @author cary.liu
	 */
	public static String getYearAndMonth() {
		Date date = new Date();
		SimpleDateFormat dateformat = new SimpleDateFormat(FORMAT_YEAR_MONTH);

		return dateformat.format(date);
	}

	/**
	 * 根据日期获取年份。
	 * 
	 * @param date
	 * @return
	 * @author cary.liu
	 */
	public static Integer getYearNo(Date date) {
		if (date == null) {
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.YEAR);
	}

	/**
	 * 获取昨天日期。
	 * 
	 * @return
	 */
	public static String getYesterday() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, -1);
		Date d = cal.getTime();
		SimpleDateFormat sp = new SimpleDateFormat(FORMAT_DATE_DEFAULT);
		return sp.format(d);
	}

	/**
	 * 判断空(私有方法)。
	 * 
	 * @param str
	 * @return
	 */
	@SuppressWarnings("unused")
	private static boolean isEmpay(String str) {
		if (str == null || "".equals("")) {
			return false;
		}
		return true;
	}
	/**FORMAT_DATETIME_NO_YEARMD
	 * 字符串转换为日期。
	 *
	 * @param dateStr
	 * @return
	 */
	public static Date string1Date(String dateStr) {
		SimpleDateFormat dateformat = new SimpleDateFormat(FORMAT_DATE_DEFAULT);
		Date date = null;
		try {
			if (dateStr == null || "".equals(dateStr)) {
				return null;
			}
			date = dateformat.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		return date;
	}
	/**FORMAT_DATETIME_NO_YEARMD
	 * 字符串转换为日期。
	 * 
	 * @param dateStr
	 * @return
	 */
	public static Date string2Date(String dateStr) {
		SimpleDateFormat dateformat = new SimpleDateFormat(FORMAT_DATETIME_NO_SECHODE);
		Date date = null;
		try {
			if (dateStr == null || "".equals(dateStr)) {
				return null;
			}
			date = dateformat.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		return date;
	}
	/**
	 * 字符串转换为日期。
	 *
	 * @param dateStr
	 * @return
	 */
	public static Date string3Date(String dateStr) {
		SimpleDateFormat dateformat = new SimpleDateFormat(FORMAT_DATETIME_NO_YEARMD);
		Date date = null;
		try {
			if (dateStr == null || "".equals(dateStr)) {
				return null;
			}
			date = dateformat.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		return date;
	}

	/**
	 * 查询上个月的开始时间
	 */
	public static String queryLastMonthStartDate() {
		Calendar c=Calendar.getInstance();
		c.add(Calendar.MONTH, -1);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String gtimelast = sdf.format(c.getTime()); //上月
		int lastMonthMaxDay=c.getActualMaximum(Calendar.DAY_OF_MONTH);
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), lastMonthMaxDay, 23, 59, 59);
		//按格式输出
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-01");
		return sdf2.format(c.getTime());
	}
	/**
	 * 查询上个月的结束时间
	 */
	public static String queryLastMonthEndDate() {
		Calendar c=Calendar.getInstance();
		c.add(Calendar.MONTH, -1);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String gtimelast = sdf.format(c.getTime()); //上月
		int lastMonthMaxDay=c.getActualMaximum(Calendar.DAY_OF_MONTH);
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), lastMonthMaxDay, 23, 59, 59);
		//按格式输出
		return sdf.format(c.getTime());
	}

	/**
	 * 查询上个月的开始时间
	 */
	public static Date queryLastMonthStartDate1() {
		Calendar c=Calendar.getInstance();
		c.add(Calendar.MONTH, -1);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String gtimelast = sdf.format(c.getTime()); //上月
		int lastMonthMaxDay=c.getActualMaximum(Calendar.DAY_OF_MONTH);
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), lastMonthMaxDay, 23, 59, 59);
		//按格式输出
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-01");
		return string1Date(sdf2.format(c.getTime()));
	}
	/**
	 * 查询上个月的结束时间
	 */
	public static Date queryLastMonthEndDate1() {
		Calendar c=Calendar.getInstance();
		c.add(Calendar.MONTH, -1);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String gtimelast = sdf.format(c.getTime()); //上月
		int lastMonthMaxDay=c.getActualMaximum(Calendar.DAY_OF_MONTH);
		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), lastMonthMaxDay, 23, 59, 59);
		//按格式输出
		return string1Date(sdf.format(c.getTime()));
	}

	/**
	 * 查询工作日天数
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public static double workDays(Date startTime, Date endTime){
		double leaveDays = 0;
		//从startTime开始循环，若该日期不是节假日或者不是周六日则请假天数+1
		Date flag = startTime;//设置循环开始日期
		Calendar cal = Calendar.getInstance();
		//循环遍历每个日期
		while(flag.compareTo(endTime)!=1){
			cal.setTime(flag);
			//判断是否为周六日
			int week = cal.get(Calendar.DAY_OF_WEEK) - 1;
			if(week == 0 || week == 6){//0为周日，6为周六
				//跳出循环进入下一个日期
				cal.add(Calendar.DAY_OF_MONTH, +1);
				flag = cal.getTime();
				continue;
			}
			//不是节假日或者周末，天数+1
			leaveDays = leaveDays + 1;
			//日期往后加一天
			cal.add(Calendar.DAY_OF_MONTH, +1);
			flag = cal.getTime();
		}
		return leaveDays;
	}

	/**
	 * 比较不同日期的时分秒差值
	 * @param date1
	 * @param date2
	 * @return
	 * @throws ParseException
	 */
	public static long getDifferTime(Date date1,Date date2) throws ParseException {
		String d1 = new SimpleDateFormat(FORMAT_DATETIME_NO_YEARMD).format(date1);
		String d2 = new SimpleDateFormat(FORMAT_DATETIME_NO_YEARMD).format(date2);
		DateFormat df = new SimpleDateFormat(FORMAT_DATETIME_NO_YEARMD);//创建日期转换对象HH:mm:ss为时分秒，年月日为yyyy-MM-dd
		Date dt1 = df.parse(d1);//将字符串转换为date类型
		Date dt2 = df.parse(d2);
		long i = dt2.getTime() - dt1.getTime();
		return i;
	}

	/**
	 * 毫秒值转Date
	 * @param date1
	 * @return
	 */
	public static Date	getDateByLong(long date1){
		Date date = new Date();
		date.setTime(date1);
		return date;
	}
//	public static void main(String[] args) throws ParseException {
//		Timestamp time = new Timestamp(System.currentTimeMillis());
//		System.out.println("timestamp:" + time);
//		System.out.println("年:" + getYearNo(new Date()));
//		System.out.println("月:" + getMonthNo(new Date()));
//		System.out.println("当前时间:" + getCurrentDateTime());
//		System.out.println("加时间:" + addDay(1));
//		System.out.println("开始时间:"+getDifferHourNumber(string2Date("2018-01-01 6:00"),string2Date("2018-01-01 7:40")));
//		System.out.println(queryLastMonthEndDate1());
//		System.out.println(workDays(string1Date("2018-05-01"),string1Date("2018-05-31")));
//		System.out.println(getTomorrow(new Date()));
//	}

    public static String getTomorrow(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.DAY_OF_MONTH, 1);
		Date d = cal.getTime();
		SimpleDateFormat sp = new SimpleDateFormat(FORMAT_DATE_DEFAULT);
		return sp.format(d);
    }

	/**
	 * 获取时间差值-年（四舍五入）
	 * @param startTime
	 * @param endTime
	 * @return
	 */
    public static Integer getDiffYear(Date startTime, Date endTime) {
		Calendar start = Calendar.getInstance();
		Calendar end = Calendar.getInstance();
		start.setTime(startTime);
		end.setTime(endTime);
		int year=end.get(Calendar.YEAR)-start.get(Calendar.YEAR);
		int month = year * 12 + end.get(Calendar.MONTH) - start.get(Calendar.MONTH);

		return Math.round(month/12);
	}

	/**
	 * 通过时间秒毫秒数判断两个时间的间隔天数
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static int differentDaysByMillisecond(Date date1,Date date2)
	{
		int days = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));
		return days;
	}

	/**
	 * 根据日期获取星期
	 * @param date
	 */
	public static String getWeek(Date date) {
		SimpleDateFormat dateFm = new SimpleDateFormat("EEEE", Locale.CHINA);
		String currSun = dateFm.format(date);
		return currSun;
	}

	/**
	 * 根据日期获取天数
	 * @param date
	 * @return
	 */
	public static int getDaysOfMonth(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
	}

	/**
	 * 获取当前日期的月份起始日期
	 * @param todayTime
	 * @return
	 * @throws ParseException
	 */
	public static Pair<Date, Date> getMonthStartAndEndDate(String todayTime) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		c.setTime(sdf.parse(todayTime));
        c.set(Calendar.DAY_OF_MONTH, 1);
		String begin = sdf.format(c.getTime());
		c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
		String end = sdf.format(c.getTime());
		Date beginDate = String2Date(begin);
		Date endDate = String2Date(end);
		return Pair.of(beginDate, endDate);
	}

	/**
	 * 判断两个日期是否为同一天
	 * @param day1
	 * @param day2
	 * @return
	 */
	public static boolean isSameDay(Date day1, Date day2) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String ds1 = sdf.format(day1);
		String ds2 = sdf.format(day2);
		if (ds1.equals(ds2)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 判断后一个日期是前一个日期的明天
	 * @param day1
	 * @param day2
	 * @return
	 */
	public static boolean isTomorrow(Date day1, Date day2) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(day1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		calendar.add(Calendar.DAY_OF_MONTH, 1);
		day1 = calendar.getTime();
		boolean isTomorrow = isSameDay(day1, day2);
		return isTomorrow;
	}

}
